// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: taekwon

#include <execinfo.h>
#include <gflags/gflags.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>

#include "coin2/exchange/base/log/strategy_logger.h"

DEFINE_string(log_root, "/home/taekwon/data/strat_proto_log", "log_root");
DEFINE_string(machine, "hive-83", "machine");
DEFINE_string(strategy_name, "lm_agg2_huobi_futures_taekwon_ltc_pilot", "strategy_name");
DEFINE_string(start_date, "2020-02-25", "start_date");
DEFINE_string(end_date, "2020-03-01", "end_date");

int main(int argc, char* argv[]) {
  using coin2::exchange::base::strategy_util::StrategyLogReader;
  google::InitGoogleLogging(argv[0]);
  gflags::ParseCommandLineFlags(&argc, &argv, true);

  coin::proto::StrategyRequestProto req;
  req.set_strategy_name(FLAGS_strategy_name);

  const size_t BUF_SIZE = 100 * 1024;

  auto begin_ts = TimestampFromString(FLAGS_start_date);
  auto end_ts = TimestampFromString(FLAGS_end_date);

  StrategyLogReader reader(req, FLAGS_log_root, FLAGS_machine, begin_ts, end_ts, BUF_SIZE);

  coin::proto::StrategyLog strat_log_proto;

  int i;
  for (i = 0; i < 100000; i++) {
    if (!reader.Read(&strat_log_proto)) {
      break;
    }

    if (strat_log_proto.og_log().type() == coin::proto::OrderGatewayLog::BALANCE) {
      continue;
    }
    if (strat_log_proto.og_log().type() == coin::proto::OrderGatewayLog::POSITION) {
      continue;
    }
    if (strat_log_proto.type() == coin::proto::StrategyLog::PNL_BALANCE) {
      continue;
    }

    LOG(INFO) << strat_log_proto.DebugString().c_str();
    LOG(INFO) << "";
  }
  return 0;
}
